package it.unicam.cs.cosy.bioshape.core.behaviours.abstraction;

import it.unicam.cs.cosy.bioshape.core.behaviours.Behaviour;

/**
 * Represents an abstract basic process following the AI framework application
 * discussed in "Towards Abstraction-Based Verification of Shape Calculus". An
 * abstract basic process has the <i>simple</i> form
 * (S<sup>#</sup>[B<sup>#</sup>]) where S<sup>#</sup> is an abstract shape and
 * B<sup>#</sup> is an abstract behaviour.<br>
 * Compound processes can be defined through the {@code AbstractProcess} class.
 * 
 * @author Federico Buti
 * 
 * @see AProcess
 */
public class ABProcess {
	Behaviour behaviour;
	final String name;

	/**
	 * Represents a simple abstract process in which a shape with a certain
	 * {@code name} has an associated {@code Behaviour}.
	 * 
	 * @param name
	 *            The name of the shape
	 * @param behaviour
	 *            The behaviour associated to the shape
	 */
	public ABProcess(String name, Behaviour behaviour) {
		this.name = name;
		this.behaviour = behaviour;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ABProcess other = (ABProcess) obj;
		if (behaviour == null) {
			if (other.behaviour != null)
				return false;
		} else if (!behaviour.equals(other.behaviour))
			return false;
		if (!getLabel().equals(other.getLabel()))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	String getLabel() {
		return name + "[" + behaviour.getLabel() + "]";
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 92821;
		int result = 1;
		result = prime * result
				+ ((behaviour == null) ? 0 : behaviour.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

}